package org.ttitfly.zuoyue.web.workflow;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springside.modules.orm.Page;
import org.ttitfly.workflow.engine.run.Task;
import org.ttitfly.zuoyue.service.workflow.TaskManager;

import com.opensymphony.xwork2.ActionSupport;

public class TaskAction extends ActionSupport {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Resource
	private TaskManager taskManager;
	
	private int id;
	private String processName;
	private String activityName;
	private int processInstanceId;
	private String processInstanceName;
	private int start;
	private int limit;
	private Page<Task> result;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getProcessName() {
		return processName;
	}

	public void setProcessName(String processName) {
		this.processName = processName;
	}

	public String getActivityName() {
		return activityName;
	}

	public void setActivityName(String activityName) {
		this.activityName = activityName;
	}

	public int getProcessInstanceId() {
		return processInstanceId;
	}

	public void setProcessInstanceId(int processInstanceId) {
		this.processInstanceId = processInstanceId;
	}

	public String getProcessInstanceName() {
		return processInstanceName;
	}

	public void setProcessInstanceName(String processInstanceName) {
		this.processInstanceName = processInstanceName;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public Page<Task> getResult() {
		return result;
	}

	public void setResult(Page<Task> result) {
		this.result = result;
	}

	public String process() {
		Task task = taskManager.get(id);
		String process = task.getProcessInstance().getProcessName();
		String result = processUrlMap.get(process);
		return result;
	}
	
	public String view() {
		Task task = taskManager.get(id);
		String process = task.getProcessInstance().getProcessName();
		String result = viewUrlMap.get(process);
		return result;
	}
	
	public String findRunningTask() {
		result = taskManager.findRunningTask(processName, activityName, 
				processInstanceId, start, limit);
		return "list";
	}
	
	public String findClosedTask() {
		result = taskManager.findClosedTask(processName, activityName, 
				processInstanceId, start, limit);
		return "list";
	}
	
	public String listHistory() {
		List<Task> tasks = taskManager.listHistory(processInstanceId);
		result = new Page<Task>();
		result.setResult(tasks);
		return "list_history";
	}
	
	private static Map<String, String> processUrlMap = new HashMap<String, String>();
	static {
		processUrlMap.put("室内分布建设", "slfbjs_process");
	}
	
	private static Map<String, String> viewUrlMap = new HashMap<String, String>();
	static {
		viewUrlMap.put("室内分布建设", "slfbjs_view");
	}
}
